home *** CD-ROM | disk | FTP | other *** search
/ Aminet 33 / Aminet 33 - October 1999.iso / Aminet / util / misc / VMM_src.lha / VMM / defs.h < prev    next >
Encoding:
C/C++ Source or Header  |  1995-12-16  |  11.6 KB  |  405 lines

  1. #include <exec/nodes.h>
  2. #include <exec/lists.h>
  3. #include <exec/memory.h>
  4. #include <exec/execbase.h>
  5. #include <exec/devices.h>
  6. #include <exec/errors.h>
  7. #include <devices/timer.h>
  8. #include <dos/dos.h>
  9. #include <dos/dosextens.h>
  10. #include <dos/dostags.h>
  11. #include <dos/filehandler.h>
  12. #include <utility/tagitem.h>
  13. #include <graphics/gfxbase.h>
  14. #include <intuition/intuition.h>
  15. #include <libraries/configvars.h>
  16. #include <libraries/commodities.h>
  17. #include <rexx/storage.h>
  18. #include <clib/exec_protos.h>
  19. #include <clib/dos_protos.h>
  20. #include <clib/graphics_protos.h>
  21. #include <clib/intuition_protos.h>
  22. #include <clib/utility_protos.h>
  23. #include <clib/expansion_protos.h>
  24. #include <clib/commodities_protos.h>
  25. #include <clib/rexxsyslib_protos.h>
  26. #include <clib/alib_protos.h>
  27. #include <string.h>
  28. #ifndef __GNUC__
  29. #include <pragmas/exec_pragmas.h>
  30. #include <pragmas/dos_pragmas.h>
  31. #include <pragmas/graphics_pragmas.h>
  32. #include <pragmas/intuition_pragmas.h>
  33. #include <pragmas/utility_pragmas.h>
  34. #include <pragmas/expansion_pragmas.h>
  35. #endif
  36. #include "shared_defs.h"
  37. #include "cat/VMM_Cat.h"
  38.  
  39. /* $Id: defs.h,v 3.8 95/12/16 18:37:07 Martin_Apel Exp $ */
  40.  
  41. #define PRIVATE static
  42.  
  43. #define POINTERTABALIGN    (POINTERS_PER_TABLE*sizeof(long))
  44. #define PAGETABALIGN       (PAGES_PER_TABLE*sizeof(long))
  45. #define PAGEALIGN          (PAGESIZE)
  46.  
  47. #define ALIGN_UP(addr,alignment) (((addr) + (alignment) - 1) & ~((alignment) - 1))
  48. #define ALIGN_DOWN(addr,alignment) ((addr) & ~((alignment) - 1))
  49.  
  50. #define ROOTOFFSET(addr)   (ROOTINDEX(addr) - ROOTINDEX(VirtAddrStart))
  51.  
  52. /* Returncodes of Evict, GetNewPage: */
  53. #define READY              TRUE
  54. #define IN_PROGRESS        FALSE
  55.  
  56. struct ExtIOReq
  57.   {
  58.   struct IOStdReq ioreq;
  59.   struct TrapStruct *TrapInfo;
  60.   };
  61.  
  62.  
  63. /* For finding partition data */
  64.  
  65. struct DOSDevParams
  66.   {
  67.   struct Device *device;
  68.   ULONG unit;
  69.   ULONG flags;
  70.   char *logical_dev_name;
  71.   struct Task *SysTask;
  72.   int heads,
  73.       secs_per_track,
  74.       low_cyl,
  75.       high_cyl,
  76.       res_start,
  77.       res_end,
  78.       block_size,
  79.       secs_per_block;
  80.   ULONG MaxTransfer;
  81.   };
  82.  
  83. struct FrameDescr
  84.   {
  85.   struct MinNode FDNode;
  86.   struct MinNode OrderNode;
  87.   ULONG PageNumOnDisk;
  88.   USHORT PageType;
  89.   BOOL   Modified;
  90.   BOOL   InFrameList;
  91.   ULONG  PhysAddr;
  92.   union
  93.     {
  94.     struct
  95.       {
  96.       ULONG *pp_PageDescr;
  97.       ULONG pp_LogAddr;
  98.       } page_params;
  99.     ULONG tp_LogTableStart;
  100.     } spec_params;
  101.   };
  102.  
  103. #define PageDescr      spec_params.page_params.pp_PageDescr
  104. #define LogAddr        spec_params.page_params.pp_LogAddr
  105. #define LogTableStart  spec_params.tp_LogTableStart
  106.  
  107. /* Defines for PageType */
  108. #define PT_PAGE  0
  109. #define PT_TABLE 1
  110. #define PT_EMPTY 2            /* only for frame descriptors */
  111.  
  112. /* Defines for state */
  113. #define PAGED_OUT          1
  114. #define COMING_IN          0
  115.  
  116. /* Defines for PageNumOnDisk */
  117. #define LOCUNUSED          0x000fffff
  118.  
  119. /* There are three special actions the pagehandler has to provide.
  120.  * These are carried out asynchroneously, i.e. they require a page
  121.  * to be read or written.
  122.  *
  123.  *                                 FaultTask       FaultAddress
  124.  * 1. Remove one frame             ReqTask              0
  125.  * 2. Reduce number of frames      REDUCE_TASK          0
  126.  * 3. Lock page                    LOCK_TASK     Page to be locked
  127.  */
  128.  
  129. #define REDUCE_TASK   0xffffffff
  130. #define LOCK_TASK     0xfffffffe
  131.  
  132. /* For EnterTask */
  133. #define INSERT_FRONT TRUE
  134. #define INSERT_BACK  FALSE
  135.  
  136. GLOBAL struct TrapStruct TrapInfo [MAX_FAULTS];
  137.  
  138. GLOBAL ULONG *RootTable;
  139. GLOBAL ULONG NumPageFrames;
  140.  
  141. GLOBAL ULONG VirtAddrStart,
  142.              VirtAddrEnd;
  143.  
  144. GLOBAL struct Task *PageHandlerTask;
  145. GLOBAL struct Process *PageHandlerProcess;        /* when paging to file */
  146. GLOBAL struct Task *PrePagerTask;
  147. GLOBAL struct Process *PrePagerProcess;           /* when paging to file */
  148. GLOBAL struct Task *StatTask;
  149. GLOBAL struct Process *VM_ManagerProcess;
  150. GLOBAL struct Process *FileHandlerProcess;        /* when paging to file */
  151.  
  152. GLOBAL void (*OrigSwitch) ();
  153. GLOBAL void (*OrigAddTask) ();
  154. GLOBAL void (*OrigAllocMem) ();
  155. GLOBAL void (*OrigFreeMem) ();
  156. GLOBAL void (*OrigAvailMem) ();
  157. GLOBAL void (*OrigWait) ();
  158. GLOBAL void (*OrigCachePreDMA) ();
  159. GLOBAL void (*OrigCachePostDMA) ();
  160. GLOBAL void (*OrigLoadSeg) ();
  161. GLOBAL void (*OrigNewLoadSeg) ();
  162. GLOBAL void (*OrigBeginIO) ();
  163. GLOBAL void (*OrigTrapHandler) ();
  164. GLOBAL void (*OrigDynMMUTrap) ();
  165. #ifdef DEBUG
  166. GLOBAL void (*OrigRemTask) ();
  167. GLOBAL void (*OrigOpen) ();
  168. GLOBAL void (*OrigStackSwap) ();
  169. GLOBAL void (*OrigAlert) ();
  170. #endif
  171. GLOBAL void (*OrigColdReboot) ();
  172. GLOBAL void (*OrigSetWindowTitles) ();
  173.  
  174. /* A few function pointers for the MMU functions */
  175. GLOBAL void (*FlushVirt) (ULONG log_addr);
  176. GLOBAL void (*CPushP) (ULONG addr);
  177. GLOBAL void (*CPushL) (ULONG addr);
  178. GLOBAL void (*PFlushP) (ULONG addr);
  179. GLOBAL void (*PFlushA) (void);
  180. GLOBAL ULONG (*GenDescr) (ULONG addr);
  181.  
  182. GLOBAL struct ExecBase   *SysBase;
  183. GLOBAL struct DosLibrary *DOSBase;
  184. GLOBAL struct Library    *IntuitionBase;
  185. GLOBAL struct GfxBase    *GfxBase;
  186. GLOBAL struct Library    *UtilityBase;
  187. GLOBAL struct Library    *ExpansionBase;
  188. GLOBAL struct Library    *CxBase;
  189. GLOBAL struct Library    *RexxSysBase;
  190. GLOBAL struct Library    *LocaleBase;
  191.  
  192. GLOBAL struct MemHeader  *VirtMem;
  193.  
  194. GLOBAL struct MsgPort *VMPort;
  195. GLOBAL struct MsgPort *RexxPort;
  196. GLOBAL struct MsgPort *InitPort;
  197. GLOBAL struct ForbiddenFreeStruct *VMToBeFreed,
  198.                                   *VMFreeRecycling;
  199.  
  200. /* A task which wants to do IO to VM puts the IORequest here */
  201. GLOBAL struct MsgPort *PrePagerPort;
  202.  
  203. /* New for 1.3: A task, which frees a substantial amount of VM, puts a
  204.  * message here to tell the pagehandler to free the corresponding
  205.  * frames
  206.  */
  207. GLOBAL struct MsgPort *PageHandlerPort;
  208.  
  209. /* Signals allocated by the VM_Manager */
  210. GLOBAL UWORD LockAckSignal;
  211.  
  212. /* Signals allocated by the PageHandler */
  213. GLOBAL UWORD PageFaultSignal,           /* Page-Fault occurred */
  214.              ReplySignal,               /* Reply from paging device */
  215.              PageHandlerQuitSignal;
  216.  
  217. /* Signals allocated by the PrePager */
  218. GLOBAL UWORD PrePagerQuitSignal,
  219.              FreeVMSignal;              /* The prepager should free some VM */
  220.  
  221.  
  222. GLOBAL UWORD StatQuitSignal;
  223.  
  224.  
  225. GLOBAL BOOL  ThisPageLocked;            /* Set by the pagehandler and read
  226.                                          * by VM_Manager when it receives
  227.                                          * the LockAckSignal
  228.                                          */
  229. GLOBAL ULONG AddedMemSize;
  230.  
  231. GLOBAL struct HashEntry *HashTab [HASHTABSIZE];
  232. GLOBAL struct HashEntry HashEntries [HASHTABSIZE];
  233.  
  234. GLOBAL ULONG NumPageFaults;
  235. GLOBAL ULONG PagesWritten;
  236. GLOBAL ULONG PagesRead;
  237. GLOBAL USHORT LowMem;
  238. GLOBAL UWORD AllocMemUsers;
  239.  
  240. GLOBAL ULONG NumLocked;
  241. GLOBAL ULONG NumTables;
  242.  
  243. /* The following variable is written by the VM_Manager before a 
  244.  * task is created which should allocate memory for a new writebuffer
  245.  * and read by that task.
  246.  */
  247. GLOBAL ULONG DesiredWriteBufferSize;
  248.  
  249. /* The following is a copy of the equally named variable in the 
  250.  * VMMConfig structure. This is done for performance reasons only
  251.  */
  252. GLOBAL ULONG MinVMAlloc;
  253.  
  254. /* The following is decremented on every FreeMem of virtual memory.
  255.  * When it decrements to zero task for collecting empty pages is 
  256.  * created.
  257.  */
  258. GLOBAL ULONG VMFreeCounter;
  259.  
  260. #define COLLECT_INTERVAL 200       /* For the above */
  261.  
  262. /* Parameters of device paging goes to (in either case) */
  263. GLOBAL struct DOSDevParams PagingDevParams;
  264.  
  265. /* Offset in bytes if !UseFile, otherwise zero */
  266. GLOBAL ULONG PartStart;
  267.  
  268. /* Partition size if !UseFile, otherwise size of paging file */
  269. GLOBAL LONG PartSize;
  270.  
  271. /* For some actions it is necessary to be sure they don't use virtual
  272.  * memory, such as error reporting. Therefore a forbid counter for
  273.  * virtual memory is established.
  274.  */
  275. GLOBAL UWORD VMD_NestCnt;  /* VMD stands for "virtual memory disable */
  276.  
  277. #define DISABLE_VM VMD_NestCnt++
  278. #define ENABLE_VM  VMD_NestCnt--
  279.  
  280. GLOBAL struct CxParams *CxParams;
  281.  
  282. GLOBAL struct List Free,
  283.                    PageReq,
  284.                    InTransit;
  285.  
  286. GLOBAL struct List FrameList;
  287.  
  288. /* There's a list of frame descriptors ordered by the time they were
  289.  * allocated. When a free is requested, a frame from the front of the list
  290.  * which is not currently involved in paging (PageDescr == RESIDENT)
  291.  * is freed. This way fragmentation of memory is reduced.
  292.  */
  293. GLOBAL struct List FrameAllocList;
  294. GLOBAL struct List LoadingTasksList;
  295.  
  296. GLOBAL struct SignalSemaphore VirtMemSema;
  297.  
  298. #ifdef USE_OWN_SEMAPHORES
  299. #define OBTAIN_VM_SEMA   VMMObtainSemaphore (&VirtMemSema)
  300. #define RELEASE_VM_SEMA  VMMReleaseSemaphore (&VirtMemSema)
  301. #define INIT_SEMA(sema)  VMMInitSemaphore (sema)
  302. #else
  303. #define OBTAIN_VM_SEMA   ObtainSemaphore (&VirtMemSema)
  304. #define RELEASE_VM_SEMA  ReleaseSemaphore (&VirtMemSema)
  305. #define INIT_SEMA(sema)  InitSemaphore (sema)
  306. #endif
  307.  
  308. GLOBAL short PageFaultsInProgress;
  309.  
  310. GLOBAL struct VMMConfig CurrentConfig;
  311. GLOBAL char PartitionName [40];
  312. GLOBAL char PartWithColon [40];
  313. /* Copy of the equally named variable in VMMConfig. For performance
  314.  * reasons only.
  315.  */
  316. GLOBAL BOOL MemTracking;
  317.  
  318. GLOBAL BOOL IsA3000;
  319.  
  320. GLOBAL BOOL ResetInProgress;
  321.  
  322. GLOBAL UWORD ProcessorType;
  323.  
  324. #define PROC_68851       0
  325. #define PROC_68030       1
  326. #define PROC_68040       2
  327. #define PROC_68060       3
  328.  
  329. #ifdef DEBUG
  330. GLOBAL ULONG InstructionFaults;
  331. #endif
  332.  
  333. #include "mmu_bits30.h"
  334. #include "protos.h"
  335.  
  336. #ifdef DEBUG
  337. #define PRINT_DEB(a,b) PrintDebugMsg(a,b)
  338. #define CHECK_CONSISTENCY CheckMemList ()
  339. #define DEBUG_MAGIC 0xac
  340. #else
  341. #define PRINT_DEB(a,b)
  342. #define CHECK_CONSISTENCY
  343. #endif
  344.  
  345. #ifdef SCHED_STAT
  346. GLOBAL ULONG FramesExamined;    /* How many frames have to be examined */
  347.                                 /* to find one to evict ? */
  348. #endif
  349.  
  350. #ifdef DEBUG
  351. GLOBAL ULONG EnforcerHits;
  352. #endif
  353.  
  354. #define USED_P(descr)      ((descr) & USED)
  355. #define MODIFIED_P(FD)     ((*((FD).PageDescr) & MODIFIED) ||\
  356.                               ((FD).Modified))
  357.  
  358. #define PGNUM_FROM_DESCR(descr) (((descr) >> 4) & 0x000fffff)
  359. #define STATE_FROM_DESCR(descr) (((descr) >> 3) & PAGED_OUT)
  360. #define TYPE_FROM_DESCR(descr)  (((descr) & 0x4) ? PT_TABLE : PT_PAGE)
  361. /* build descriptor for a swapped page */
  362. #define BUILD_DESCR(pgnum,state,type) (((pgnum) << 4) | ((state) << 3) |\
  363.                                        ((type) << 2) | INVALID)
  364.  
  365. /* A page descriptor looks like the following when the page is resident:
  366.  * 31 ... 12  11  10  9  8  7  6  5  4  3  2  1  0
  367.  * Phys.Addr  UR   G U1 U0  S   CM   M  U  W  1  1
  368.  * The UR bit is used for the locked state.
  369.  *
  370.  * ************************************************
  371.  * When the page is swapped out it looks like this:
  372.  * 31..24  23..4    3     2  1  0
  373.  * unused PageNum State Type 0  0
  374.  * This gives 20 bits for the slot number, address space is
  375.  * 2 ** 20 * 2 ** 12 = 4 GB
  376.  */
  377.  
  378. /* For 68040 this means copyback */
  379. #define CACHEABLE             ((ULONG)((ProcessorType >= PROC_68040) ?\
  380.                                          (0x20) : (0x00)))
  381. /* For 68040 this means serialized */
  382. #define NONCACHEABLE          0x40
  383.  
  384. #define CACHE_MODE            CACHEABLE
  385.  
  386. /* Uses unused bits of page descriptor */
  387. #define LOCKED                ((ULONG)((ProcessorType >= PROC_68040) ? \
  388.                                          (0x800) : (0x20)))
  389.  
  390. /* These have to be defined separately, because they are used on MMU tables
  391.  * the system or Enforcer have built.
  392.  */
  393.  
  394. #define TABLE_RESIDENT_P(descr) ((ProcessorType >= PROC_68040) ? ((descr) & 0x2) : \
  395.                                  (((descr) & 0x3) == TABLE_RESIDENT))
  396.  
  397. #define PAGE_RESIDENT_P(descr)  ((ProcessorType >= PROC_68040) ? ((descr) & 0x1) : \
  398.                                  (((descr) & 0x3) == PAGE_RESIDENT))
  399.  
  400. #define TABLE_INVALID_P(descr)  (!TABLE_RESIDENT_P(descr))
  401. #define PAGE_INVALID_P(descr)   (!PAGE_RESIDENT_P(descr))
  402. #define LOCKED_P(descr)         ((descr) & LOCKED)
  403.  
  404. #include "errors.h"
  405.